import java.util.Scanner;

public class password {
    public static void main(String[] args) {
    Scanner scr=new Scanner(System.in);
<<<<<<< HEAD
    System.out.println("请输入序号选择功能\n" +
=======
    System.out.println("请输入序号选择\n" +
>>>>>>> 45648b9cf8b7f280429d50ebc8b8b4327764e776
                       "1.加密密码\n"+
                        "2.解密密码 ");
    int choice=scr.nextInt();
//让用户选择功能
    switch(choice){
        case 1:
            System.out.print("请输入要加密的密码");
            String passwordtoencrypt=scr.next();
            System.out.println("加密后的密码为:"+encrypt(passwordtoencrypt));
            break;
        case 2:
            System.out.print("请输入要解密的密码");
            String passwordtodecrypt=scr.next();
            System.out.println("解密后的密码为:"+decrypt(passwordtodecrypt));
            break;
    }
    scr.close();
    }
//加密功能
    public static String encrypt(String password){
        StringBuilder encrytedPassword=new StringBuilder();
        for(int i=0;i<password.length();i++){
            char encry=password.charAt(i);
            int ascll=encry+(i+1)+3;
            encrytedPassword.append((char)ascll);
        }
        char a,b;
        a= encrytedPassword.charAt(0);
        b= encrytedPassword.charAt(encrytedPassword.length()-1);
        encrytedPassword.setCharAt(0,b);
        encrytedPassword.setCharAt(encrytedPassword.length()-1,a);
        encrytedPassword=encrytedPassword.reverse();
        return encrytedPassword.toString();
    }
//解密功能
    public static String decrypt(String encrytedPassword){
        StringBuilder decrytedPassword=new StringBuilder(encrytedPassword);
        char c,d;
        c= decrytedPassword.charAt(0);
        d= decrytedPassword.charAt(decrytedPassword.length()-1);
        decrytedPassword.setCharAt(0,d);
        decrytedPassword.setCharAt(decrytedPassword.length()-1,c);
        decrytedPassword=decrytedPassword.reverse();
        StringBuilder password=new StringBuilder();
        for(int i=0;i<decrytedPassword.length();i++){
            char decry=decrytedPassword.charAt(i);
            int ascll=decry-(i+1)-3;
            password.append((char)ascll);
        }
        return password.toString();
    }

}